<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('商城零售配件信息列表')" />
    <th:block th:include="include :: layout-latest-css" />
    <th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
<div class="ui-layout-west">
    <div class="box box-main">
        <div class="box-header">
            <div class="box-title">
                <i class="fa icon-grid"></i> 产品分类
            </div>
            <div class="box-tools pull-right">
                <a type="button" class="btn btn-box-tool" href="#" onclick="dept()" title="管理分类"><i class="fa fa-edit"></i></a>
                <button type="button" class="btn btn-box-tool" id="btnExpand" title="展开" style="display:none;"><i class="fa fa-chevron-up"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnCollapse" title="折叠"><i class="fa fa-chevron-down"></i></button>
                <button type="button" class="btn btn-box-tool" id="btnRefresh" title="刷新分类"><i class="fa fa-refresh"></i></button>
            </div>
        </div>
        <div class="ui-layout-content">
            <div id="tree" class="ztree"></div>
        </div>
    </div>
</div>
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input type="hidden" id="partsType" name="partsType">
                    <input type="hidden" id="parentId" name="parentId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>厂家名称：</label>
                                <input type="text" name="factoryName"/>
                            </li>
                            <li>
                                <label>产品名称：</label>
                                <input type="text" name="partsName"/>
                            </li>
                            <li>
                                <label style="width: 120px;">是否热门推荐：</label>
                                <select name="isHotPush" th:with="type=${@dict.getType('zsyh_yesno')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label style="width: 120px;">是否上架：</label>
                                <select name="isShow" th:with="type=${@dict.getType('zsyh_yesno')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="zsyh:parts:add">
                    <i class="fa fa-plus"></i> 添加新产品
                </a>
                <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="zsyh:parts:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="zsyh:parts:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>-->
                <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="zsyh:parts:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-bordered">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: layout-latest-js" />
<th:block th:include="include :: ztree-js" />
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('zsyh:parts:edit')}]];
    var removeFlag = [[${@permission.hasPermi('zsyh:parts:remove')}]];
    var isTodayHotDatas = [[${@dict.getType('zsyh_yesno')}]];
    var isNewPushDatas = [[${@dict.getType('zsyh_yesno')}]];
    var isGoodChoiceDatas = [[${@dict.getType('zsyh_yesno')}]];
    var isHotPushDatas = [[${@dict.getType('zsyh_yesno')}]];
    var isShowDatas = [[${@dict.getType('zsyh_yesno')}]];
    var isPostDatas = [[${@dict.getType('zsyh_yesno')}]];
    var prefix = ctx + "zsyh/sellParts";
    var prefixAttri = ctx + "zsyh/sellPartsAttribute";

    $(function() {
        var panehHidden = false;
        if ($(this).width() < 769) {
            panehHidden = true;
        }
        $('body').layout({ initClosed: panehHidden, west__size: 185 });
        queryPartsList();
        queryTypeTree();
    });

    function queryTypeTree() {
        var url = ctx + "zsyh/partstype/treeData";
        var options = {
            url: url,
            expandLevel: 0,
            onClick : zOnClick
        };
        $.tree.init(options);

        function zOnClick(event, treeId, treeNode) {
            debugger;
            $("#partsType").val(treeNode.id);
            $("#parentId").val(treeNode.pId);
            $.table.search();
        }
    }

    $('#btnExpand').click(function() {
        $._tree.expandAll(true);
        $(this).hide();
        $('#btnCollapse').show();
    });

    $('#btnCollapse').click(function() {
        $._tree.expandAll(false);
        $(this).hide();
        $('#btnExpand').show();
    });

    $('#btnRefresh').click(function() {
        queryTypeTree();
    });

    function queryPartsList() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            detailView: true,
            onExpandRow : function(index, row, $detail) {
                initChildTable(index, row, $detail);
            },
            modalName: "产品管理",
            columns: [{
                field : 'Number',
                title : '序号',
                align: 'center',
                width: 20,
                formatter : function(value, row, index) {
                    var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                    var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                    return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                }
            },
                {
                    field: 'id',
                    title: '产品Id',
                    visible: false
                },
                /*{
                    field: 'factoryId',
                    title: '厂家信息Id'
                },*/
                {
                    field: 'partsImages',
                    title: '产品主图',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'partsName',
                    align: 'center',
                    title: '产品名称'
                },
                /*{
                    field: 'partsNumber',
                    align: 'center',
                    title: '产品编码'
                },*/
                /*{
                    field: 'partsUnit',
                    align: 'center',
                    title: '产品单位'
                },*/
                {
                    field: 'firstName',
                    align: 'center',
                    title: '一级产品分类'
                },{
                    field: 'secondName',
                    align: 'center',
                    title: '二级产品分类'
                }, {
                    field: 'factoryName',
                    align: 'center',
                    title: '厂家名称'
                },
                /*{
                    field: 'partsBrand',
                    title: '配件品牌'
                },*/
                /*{
                    field: 'partsDetails',
                    title: '配件描述'
                },*/

                /*{
                    field: 'partsRemarks',
                    title: '配件详细信息'
                },*/
                /*{
                    field: 'isTodayHot',
                    title: '是否今日热卖',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isTodayHotDatas, value);
                    }
                },
                {
                    field: 'isNewPush',
                    title: '是否新品推荐',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isNewPushDatas, value);
                    }
                },
                {
                    field: 'isGoodChoice',
                    title: '是否好物优选',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isGoodChoiceDatas, value);
                    }
                },*/
                {
                    field: 'isShow',
                    title: '是否上架',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(isShowDatas, value);
                    }
                },
                {
                    field: 'isHotPush',
                    title: '是否热门推荐',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(isHotPushDatas, value);
                    }
                },
                /*{
                    field: 'isPost',
                    title: '是否包邮',
                    align: 'center',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isPostDatas, value);
                    }
                },*/
                /*{
                    field: 'partsQuantity',
                    title: '订购最低数量'
                },*/

                /*{
                    field: 'isShowProvince',
                    title: '省级是否上架 1是 0否',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isShowProvinceDatas, value);
                    }
                },*/
                /*{
                    field: 'isShowCity',
                    title: '市县级是否上架 1是 0否',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isShowCityDatas, value);
                    }
                },*/
                /*{
                    field: 'isShowWorker',
                    title: '维修师傅是否上架 1是 0否',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isShowWorkerDatas, value);
                    }
                },*/
                /*{
                    field: 'partsClassification',
                    title: '分类 1配件 2整机',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(partsClassificationDatas, value);
                    }
                },*/

                /*{
                    field: 'partsLogo',
                    title: '配件图标'
                },*/
                /*{
                    field: 'partsDamageDetails',
                    title: '补助金使用方法'
                },
                {
                    field: 'partsTaobaourl',
                    title: '淘宝连接'
                },*/
                /*{
                    field: 'partsVideourl',
                    title: '主图视频'
                },*/
                /*{
                    field: 'isViewAttrs',
                    title: '是否显示属性信息',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(isViewAttrsDatas, value);
                    }
                },*/
                /*{
                    field: 'partsConditions',
                    title: '赔付条件'
                },*/
               /* {
                    field: 'partsHasGrant',
                    title: '是否有补助金',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(partsHasGrantDatas, value);
                    }
                },
                {
                    field: 'partsDistinguish',
                    title: '产品商标',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(partsDistinguishDatas, value);
                    }
                },*/
                {
                    field: 'partsSort',
                    title: '排序',
                    align: 'center',
                    sortable:true
                },
                /*{
                    field: 'partsRebateType',
                    title: '返点方式 1差额 2百分比',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(partsRebateTypeDatas, value);
                    }
                },*/
                /*{
                    field: 'partsAttention',
                    title: '注意事项'
                },
                {
                    field: 'partsInstructions',
                    title: '使用说明'
                },*/
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a style="margin-left: 3px" class="btn btn-primary btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="batchUpdate(\'' + row.id + '\')"><i class="fa fa-edit"></i>批量添加产品规格</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    };


    initChildTable = function(index, row, $detail) {
        var childTable = $detail.html('<table style="table-layout:fixed"></table>').find('table');
        $(childTable).bootstrapTable({
            url: prefix + "/listChild",
            updateUrl: prefixAttri + "/edit/{id}",
            modalName: "产品规格",
            method: 'post',
            sidePagination: "server",
            contentType: "application/x-www-form-urlencoded",
            queryParams: {
                mid: row.id
            },
            columns: [
                {
                    field : 'Number',
                    title : '序号',
                    align: 'center',
                    width: 20,
                    formatter : function(value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;//通过表的#id 可以得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;//通过表的#id 可以得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;//返回每条的序号： 每页条数 * （当前页 - 1 ）+ 序号
                    }
                },
                {
                    field: 'id',
                    title: '产品规格',
                    align: 'center',
                    visible: false
                },
                {
                    field: 'attributeLogo',
                    align: 'center',
                    title: '规格主图',
                    formatter: function (value, row, index) {
                        return $.table.imageView(value);
                    }
                },
                {
                    field: 'attributeName',
                    align: 'center',
                    title: '规格名称'
                },

                {
                    field: 'attributeRetailPrice',
                    align: 'center',
                    title: '统一零售价'
                },
                {
                    field: 'attributeWholesalePrice',
                    align: 'center',
                    title: '统一批发价'
                },
                {
                    field: 'attributeShippingFee',
                    align: 'center',
                    title: '运费'
                },
                {
                    field: 'isShow',
                    title: '是否上架',
                    align: 'center',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(isShowDatas, value);
                    }
                },
                {
                    field: 'attributeSort',
                    align: 'center',
                    title: '排序'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="editAttribute(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="removeAttribute11(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
        });
    };

    function batchUpdate(id) {
        $.modal.openTab("批量添加规格", ctx+"zsyh/sellPartsAttribute/view/"+id,'800', '800');
    }

    function editAttribute(id) {
        $.modal.open("修改产品规格" , prefixAttri + "/edit/"+id);
    }

    function removeAttribute11(id) {
        $.modal.confirm("确定删除该条信息吗？", function() {
            debugger;
            var url =prefixAttri + "/remove";
            var data = { "ids": id };
            $.operate.submit(url, "post", "json", data,function () {
                $("#bootstrap-table").bootstrapTable('refresh');
            });
        });
    }

    function dept() {
        var url = ctx + "zsyh/partsTypeDetail";
        $.modal.openTab("服务大类管理", url);
    }

</script>
</body>
</html>